package com.dhy.generator;

import com.dhy.model.MainTemplateConfig;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

public class MainGenerator {
    public static void main(String[] args) throws TemplateException, IOException {
        String projectPath = System.getProperty("user.dir");
//        System.out.println(projectPath);
        String inputPath = projectPath + File.separator + "demo-project" + File.separator + "acm-template";
        String outputPath = projectPath + File.separator + "out";

        //静态文件生成
        StaticGenerator.copyFilesByHutool(inputPath, outputPath);

        //动态文件生成
        String templatePath = projectPath + File.separator + "generator-basic" + File.separator +
                "src/main/resources/templates/MainTemplate.java.ftl";
        //demo-project/acm-template/src/com/yupi/acm/MainTemplate.java
        String outputPath2 = outputPath + File.separator + "acm-template/src/com/yupi/acm/MainTemplate.java";
        //数据结构
        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();
        mainTemplateConfig.setAuthor("dhyyy");
        mainTemplateConfig.setOutputText("输出信息");
        mainTemplateConfig.setLoop(true);
        DynamicGenerator.doGenerate(templatePath,outputPath2,mainTemplateConfig);
    }

    public static void doGenerate(Object model) throws TemplateException, IOException {
        String projectPath = System.getProperty("user.dir");
//        System.out.println(projectPath);
        String inputPath = projectPath + File.separator + "demo-project" + File.separator + "acm-template";
        String outputPath = projectPath + File.separator + "out";

        //静态文件生成
        StaticGenerator.copyFilesByHutool(inputPath, outputPath);

        //动态文件生成
        String templatePath = projectPath + File.separator + "generator-basic" + File.separator +
                "src/main/resources/templates/MainTemplate.java.ftl";
        //demo-project/acm-template/src/com/yupi/acm/MainTemplate.java
        String outputPath2 = outputPath + File.separator + "acm-template/src/com/yupi/acm/MainTemplate.java";

        DynamicGenerator.doGenerate(templatePath,outputPath2,model);
    }
}
